package model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * 图书类别实体
 */
public class BookType {
    private int id; //编号
    private String bookTypeName; //图书类别名称
    private String bookTypeDesc; //备注
    private boolean available=true;
    public BookType(String bookTypeName,String bookTypeDesc){
        this.bookTypeName=bookTypeName;
        this.bookTypeDesc=bookTypeDesc;
    }
    public BookType(int id,String bookTypeName,String bookTypeDesc){
        this.id=id;
        this.bookTypeName=bookTypeName;
        this.bookTypeDesc=bookTypeDesc;
    }
    public BookType(){
       super();
    }

    public boolean isAvailable(Connection con,Book book) throws Exception {
        String sql="select bt.available from t_bookType bt join t_book tb on bt.id=tb.bookTypeId ";
        PreparedStatement pstmt=con.prepareStatement(sql);
        ResultSet rs=pstmt.executeQuery();
        while (rs.next()){
            int a=rs.getInt("available");
            if(a==1){
                return true;
            }
        }
        return false;
    }

    public int getId() {
        return id;
    }

    public String getBookTypeName() {
        return bookTypeName;
    }

    public String getBookTypeDesc() {
        return bookTypeDesc;
    }

    public void setId(int id) {
        this.id = id;
    }

    public void setAvailable(boolean available) {
        this.available = available;
    }

    public void setBookTypeName(String bookTypeName) {
        this.bookTypeName = bookTypeName;
    }

    public void setBookTypeDesc(String bookTypeDesc) {
        this.bookTypeDesc = bookTypeDesc;
    }

    @Override
    public String toString() {
        return bookTypeName;
    }
}
